/**
 * 
 */
package com.td.framework.webmanager.login;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.td.framework.utils.StringUtils;
import com.td.framework.webmanager.domain.AppsysQxfwjlgx;
import com.td.framework.webmanager.domain.AppsysYmgnan;

/**
 * 
 *  Title:登录用户类;
 *  Description: 定义登录用户基本信息;
 *  Copyright: Copyright (c) 2008 
 *  Company 北京水软科技有限公司
 * 
 * @author FLT006
 * @version 1.0
 */
public class UserInfo implements java.io.Serializable {
	
	private static final long serialVersionUID = 8104688830906360748L;
	private Long id;
	private String yhbh;//用户编号;
	private String yhm;//用户名称;
	private Long rybh;//人员编号,与人员表关联;
	private String xm;//姓名
	private String zw;//职务
	private String bmbh;// 部门编号;
	private String bmgdbh;//部门固定编号，定长为10位，可表示5级部门;
	private String bmmc;// 部门名称;
	private String sjbmbh;//上级部门编号;
	private String sjbmgdbh;//上级部门固定编号，定长为10位，可表示5级部门;
	private String sjbhmc;//上级部门名称;
	private Date dlsj = null;//登录时间;
	private String xtmc = "";//登录系统名称
	private String mima;//密码;
	private List<AppsysYmgnan> ymgnList = null;//页面功能按钮List;
	private List<UserInfoQxxzzdInfo> xzzdList;//用户权限(页面功能)List;
	private List<AppsysQxfwjlgx> fwjlgxList;//用户权限(页面功能)List;
	
	/**
	 * @toDo:get
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @toDo:set
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @toDo:get
	 * @return the yhbh
	 */
	public String getYhbh() {
		return yhbh;
	}
	/**
	 * @toDo:set
	 * @param yhbh the yhbh to set
	 */
	public void setYhbh(String yhbh) {
		this.yhbh = yhbh;
	}
	/**
	 * @toDo:get
	 * @return the yhm
	 */
	public String getYhm() {
		return yhm;
	}
	/**
	 * @toDo:set
	 * @param yhm the yhm to set
	 */
	public void setYhm(String yhm) {
		this.yhm = yhm;
	}
	/**
	 * @toDo:get
	 * @return the rybh
	 */
	public Long getRybh() {
		return rybh;
	}
	/**
	 * @toDo:set
	 * @param rybh the rybh to set
	 */
	public void setRybh(Long rybh) {
		this.rybh = rybh;
	}
	/**
	 * @toDo:get
	 * @return the xm
	 */
	public String getXm() {
		return xm;
	}
	/**
	 * @toDo:set
	 * @param xm the xm to set
	 */
	public void setXm(String xm) {
		this.xm = xm;
	}
	/**
	 * @toDo:get
	 * @return the zw
	 */
	public String getZw() {
		return zw;
	}
	/**
	 * @toDo:set
	 * @param zw the zw to set
	 */
	public void setZw(String zw) {
		this.zw = zw;
	}
	/**
	 * @toDo:get
	 * @return the bmbh
	 */
	public String getBmbh() {
		return bmbh;
	}
	/**
	 * @toDo:set
	 * @param bmbh the bmbh to set
	 */
	public void setBmbh(String bmbh) {
		this.bmbh = bmbh;
	}
	/**
	 * @return the bmgdbh
	 */
	public String getBmgdbh() {
		return bmgdbh;
	}
	/**
	 * @param bmgdbh the bmgdbh to set
	 */
	public void setBmgdbh(String bmgdbh) {
		this.bmgdbh = bmgdbh;
	}
	/**
	 * @toDo:get
	 * @return the bmmc
	 */
	public String getBmmc() {
		return bmmc;
	}
	/**
	 * @toDo:set
	 * @param bmmc the bmmc to set
	 */
	public void setBmmc(String bmmc) {
		this.bmmc = bmmc;
	}
	/**
	 * @toDo:get
	 * @return the mima
	 */
	public String getMima() {
		return mima;
	}
	/**
	 * @toDo:set
	 * @param mima the mima to set
	 */
	public void setMima(String mima) {
		this.mima = mima;
	}

	/**
	 * toDo:get
	 * @return xzzdList
	 */
	public List<UserInfoQxxzzdInfo> getXzzdList() {
		return xzzdList;
	}
	/**
	 * toDo:set
	 * @param xzzdList 
	 */
	public void setXzzdList(List<UserInfoQxxzzdInfo> xzzdList) {
		this.xzzdList = xzzdList;
	}
	/**
	 * toDo:get
	 * @return fwjlgxList
	 */
	public List<AppsysQxfwjlgx> getFwjlgxList() {
		return fwjlgxList;
	}
	/**
	 * toDo:set
	 * @param fwjlgxList 
	 */
	public void setFwjlgxList(List<AppsysQxfwjlgx> fwjlgxList) {
		this.fwjlgxList = fwjlgxList;
	}
	/**
	 * toDo:根据页面编号读出页面限制按钮权限list
	 * @param ymbh
	 * @return list
	 */
	@SuppressWarnings("unchecked")
	public List<AppsysYmgnan> getQxymgnanList(String ymbh)
	{
		List<AppsysYmgnan> list = null;
		if(ymgnList!=null&&!ymgnList.isEmpty())
		{
			list = new ArrayList();
			for (Iterator iterator = ymgnList.iterator(); iterator.hasNext();) {
				AppsysYmgnan ymgn = (AppsysYmgnan) iterator
						.next();
				if(ymgn.getYmbh().equals(ymbh))
				{
					list.add(ymgn);
				}
			}
		}
		return list;
	}
	/**
	 * toDo:根据页面编号读出页面限制按钮限制编号
	 * @param ymbh
	 * @return ymgnans
	 */
	@SuppressWarnings("unchecked")
	public String getQxymgnans(String ymbh)
	{
		String ymgnans = "";
		if(ymgnList!=null&&!ymgnList.isEmpty())
		{
			for (Iterator iterator = ymgnList.iterator(); iterator.hasNext();) {
				AppsysYmgnan ymgn = (AppsysYmgnan) iterator
						.next();
				if(ymgn.getYmbh().equals(ymbh))
				{
					ymgnans +=ymgn.getAnbh()+";";
				}
			}
		}
		return ";"+ymgnans;
	}
	/**
	 * toDo:根据页面编号读出页面限制字段权限list
	 * @param ymbh
	 * @return list;
	 */
	@SuppressWarnings("unchecked")
	public List<UserInfoQxxzzdInfo> getQxxzzdList(String ymbh)
	{
		List<UserInfoQxxzzdInfo> list = null;
		if(xzzdList!=null&&!xzzdList.isEmpty())
		{
			list = new ArrayList();
			for (Iterator iterator = xzzdList.iterator(); iterator.hasNext();) {
				UserInfoQxxzzdInfo userInfoQxxzzdInfo = (UserInfoQxxzzdInfo) iterator
						.next();
				if(userInfoQxxzzdInfo.getYmbh().equals(ymbh))
				{
					list.add(userInfoQxxzzdInfo);
				}
			}
		}
		return list;
	}
	/**
	 * toDo:根据页面编号读出页面限制字段权
	 * @param ymbh
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String  getQxxzzd(String ymbh)
	{
		String qxxzzd = "";
		if(xzzdList!=null&&!xzzdList.isEmpty())
		{
			for (int i=0; i<xzzdList.size();i++) {
				UserInfoQxxzzdInfo userInfoQxxzzdInfo = (UserInfoQxxzzdInfo) xzzdList.get(i);
				if(userInfoQxxzzdInfo.getYmbh().equals(ymbh))
				{
					if(i==xzzdList.size()-1)
					{
						qxxzzd +=userInfoQxxzzdInfo.getZdywmc();
					}
					else
					{
						qxxzzd +=userInfoQxxzzdInfo.getZdywmc()+",";
					}
				}
			}
		}
		return qxxzzd;
	}
	/**
	 * toDo:根据页面编号、字段中文名称读出限制字段英文名称
	 * @param ymbh
	 * @param zdmc
	 * @return zdywmc
	 */
	@SuppressWarnings("unchecked")
	public String getQxxzdywmc(String ymbh,String zdmc)
	{
		String zdywmc = "";
		if(xzzdList!=null&&!xzzdList.isEmpty())
		{
			for (Iterator iterator = xzzdList.iterator(); iterator.hasNext();) {
				UserInfoQxxzzdInfo userInfoQxxzzdInfo = (UserInfoQxxzzdInfo) iterator
						.next();
				if(userInfoQxxzzdInfo.getYmbh().equals(ymbh)&&userInfoQxxzzdInfo.getZdywmc().equals(zdmc))
				{
					zdywmc =userInfoQxxzzdInfo.getZdywmc();
					break;
				}
			}
		}
		return zdywmc;
	}
	/**
	 * toDo:根据页面编号读出页面限制条件权限list
	 * @param ymbh
	 * @return list;
	 */
	@SuppressWarnings("unchecked")
	public List<AppsysQxfwjlgx> getQxfwjlgxList(String ymbh)
	{
		List<AppsysQxfwjlgx> list= null;
		if(fwjlgxList!=null&&!fwjlgxList.isEmpty())
		{
			list = new ArrayList();
			for (Iterator iterator = fwjlgxList.iterator(); iterator.hasNext();) {
				AppsysQxfwjlgx appsysQxfwjlgx = (AppsysQxfwjlgx) iterator
						.next();
				if(appsysQxfwjlgx.getYmbh().equals(ymbh))
				{
					list.add(appsysQxfwjlgx);
				}
			}
		}
		return list;
	}
	/**
	 * @param ymbh
	 * @param prefix
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getQxxztjs(String ymbh,String prefix)
	{
		StringBuffer buffer = new StringBuffer().append("");
		if(!prefix.trim().equals(""))
		{
			prefix += ".";
			
		}
		else
		{
			prefix = "";
		}
		if(fwjlgxList!=null&&!fwjlgxList.isEmpty())
		{
			int beginTemp = 0;
			int endTemp = 0;
			String beginDate = "";
			String endDate = "";
			HashMap hashMap = new HashMap();
			for (Iterator iterator = fwjlgxList.iterator(); iterator.hasNext();) {
				AppsysQxfwjlgx appsysQxfwjlgx = (AppsysQxfwjlgx) iterator
						.next();
				if(appsysQxfwjlgx.getYmbh().equals(ymbh)&&appsysQxfwjlgx.getSjlx()==0)
				{
					if(hashMap.containsKey(prefix+appsysQxfwjlgx.getZdywmc()+"@0"))
					{
						hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+"@0", hashMap.get(prefix+appsysQxfwjlgx.getZdywmc()+"@0")+","+appsysQxfwjlgx.getXztj());
					}
					else
					{
						hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+"@0", appsysQxfwjlgx.getXztj());
					}
				}
				else if(appsysQxfwjlgx.getYmbh().equals(ymbh)&&appsysQxfwjlgx.getSjlx()==1)
				{
					//起始日期条件
					if(!(appsysQxfwjlgx.getXstj()+"").equals("")&&!(appsysQxfwjlgx.getXstj()+"").equals("null"))
					{
						if(hashMap.containsKey(prefix+appsysQxfwjlgx.getZdywmc()+" >= to_date@1"))
						{
							if(beginTemp>Integer.parseInt(appsysQxfwjlgx.getXstj().replace("-", "")))
							{
								beginTemp=Integer.parseInt(appsysQxfwjlgx.getXstj().replace("-", ""));
								beginDate = appsysQxfwjlgx.getXstj();
							}
						}
						else
						{
							beginDate = appsysQxfwjlgx.getXstj();
							beginTemp=Integer.parseInt(appsysQxfwjlgx.getXstj().replace("-", ""));
							hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+" >= to_date@1", beginDate);
						}
					}
					//截至日期条件
					if(!(appsysQxfwjlgx.getXztj()+"").equals("")&&!(appsysQxfwjlgx.getXztj()+"").equals("null"))
					{
						if(hashMap.containsKey(prefix+appsysQxfwjlgx.getZdywmc()+" <= to_date@1"))
						{
							if(endTemp<Integer.parseInt(appsysQxfwjlgx.getXztj().replace("-", "")))
							{
								endTemp=Integer.parseInt(appsysQxfwjlgx.getXztj().replace("-", ""));
								endDate = appsysQxfwjlgx.getXztj();
								hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+" <= to_date@1", endDate);
							}
						}
						else
						{
							endDate = appsysQxfwjlgx.getXztj();
							endTemp=Integer.parseInt(appsysQxfwjlgx.getXztj().replace("-", ""));
							hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+" <= to_date@1", endDate);
						}
					}
				}
			}
			String key = "";
			for (Iterator iterator = hashMap.entrySet().iterator(); iterator.hasNext();) {
				Map.Entry entry = (Map.Entry) iterator.next();
				key = entry.getKey()+"";
				if(key.lastIndexOf("@0")>0)
				{
					buffer.append(" and instr(',"+StringUtils.removeSameString(entry.getValue()+"",",")+"',','||"+key.substring(0,key.lastIndexOf("@0"))+"||',',1)>0 ");
				}
				else if(key.lastIndexOf("@1")>0)
				{
					buffer.append(" and "+key.substring(0,key.lastIndexOf("@1"))+"('"+entry.getValue()+"','yyyy-mm-dd') ");
				}
			}
			hashMap.clear();
		}
		return buffer.toString();
	}
	/**
	 * @param ymbh
	 * @param prefix
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getQxxztjs(String ymbh,String prefix,String zdmc,String defaultVaue)
	{
		StringBuffer buffer = new StringBuffer().append("");
		if(!prefix.trim().equals(""))
		{
			prefix += ".";
			
		}
		else
		{
			prefix = "";
		}
		if(fwjlgxList!=null&&!fwjlgxList.isEmpty())
		{
			int beginTemp = 0;
			int endTemp = 0;
			String beginDate = "";
			String endDate = "";
			HashMap hashMap = new HashMap();
			for (Iterator iterator = fwjlgxList.iterator(); iterator.hasNext();) {
				AppsysQxfwjlgx appsysQxfwjlgx = (AppsysQxfwjlgx) iterator
						.next();
				if(appsysQxfwjlgx.getYmbh().equals(ymbh)&&appsysQxfwjlgx.getSjlx()==0)
				{
					if(hashMap.containsKey(prefix+appsysQxfwjlgx.getZdywmc()+"@0"))
					{
						hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+"@0", hashMap.get(prefix+appsysQxfwjlgx.getZdywmc()+"@0")+","+appsysQxfwjlgx.getXztj());
					}
					else
					{
						hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+"@0", appsysQxfwjlgx.getXztj());
					}
				}
				else if(appsysQxfwjlgx.getYmbh().equals(ymbh)&&appsysQxfwjlgx.getSjlx()==1)
				{
					//起始日期条件
					if(!(appsysQxfwjlgx.getXstj()+"").equals("")&&!(appsysQxfwjlgx.getXstj()+"").equals("null"))
					{
						if(hashMap.containsKey(prefix+appsysQxfwjlgx.getZdywmc()+" >= to_date@1"))
						{
							if(beginTemp>Integer.parseInt(appsysQxfwjlgx.getXstj().replace("-", "")))
							{
								beginTemp=Integer.parseInt(appsysQxfwjlgx.getXstj().replace("-", ""));
								beginDate = appsysQxfwjlgx.getXstj();
							}
						}
						else
						{
							beginDate = appsysQxfwjlgx.getXstj();
							beginTemp=Integer.parseInt(appsysQxfwjlgx.getXstj().replace("-", ""));
							hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+" >= to_date@1", beginDate);
						}
					}
					//截至日期条件
					if(!(appsysQxfwjlgx.getXztj()+"").equals("")&&!(appsysQxfwjlgx.getXztj()+"").equals("null"))
					{
						if(hashMap.containsKey(prefix+appsysQxfwjlgx.getZdywmc()+" <= to_date@1"))
						{
							if(endTemp<Integer.parseInt(appsysQxfwjlgx.getXztj().replace("-", "")))
							{
								endTemp=Integer.parseInt(appsysQxfwjlgx.getXztj().replace("-", ""));
								endDate = appsysQxfwjlgx.getXztj();
								hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+" <= to_date@1", endDate);
							}
						}
						else
						{
							endDate = appsysQxfwjlgx.getXztj();
							endTemp=Integer.parseInt(appsysQxfwjlgx.getXztj().replace("-", ""));
							hashMap.put(prefix+appsysQxfwjlgx.getZdywmc()+" <= to_date@1", endDate);
						}
					}
				}
			}
			String key = "";
			int num = 0;
			for (Iterator iterator = hashMap.entrySet().iterator(); iterator.hasNext();) {
				Map.Entry entry = (Map.Entry) iterator.next();
				key = entry.getKey()+"";
				if(key.lastIndexOf("@0")>0)
				{
					if(!"".equals(zdmc)&&!"".equals(defaultVaue)
							&&key.substring(0,key.lastIndexOf("@0")).equalsIgnoreCase(zdmc))
					{
						buffer.append(" and instr(',"+StringUtils.removeSameString(entry.getValue()+","+defaultVaue,",")+"',','||"+key.substring(0,key.lastIndexOf("@0"))+"||',',1)>0 ");
						num++;
					}
					else
					{
						buffer.append(" and instr(',"+StringUtils.removeSameString(entry.getValue()+"",",")+"',','||"+key.substring(0,key.lastIndexOf("@0"))+"||',',1)>0 ");
					}
				}
				else if(key.lastIndexOf("@1")>0)
				{
					buffer.append(" and "+key.substring(0,key.lastIndexOf("@1"))+"('"+entry.getValue()+"','yyyy-mm-dd') ");
				}
			}
			hashMap.clear();
			if(num==0&&!"".equals(zdmc)&&!"".equals(defaultVaue))
			{
				buffer.append(" and instr(',"+defaultVaue+",',','||"+zdmc+"||',',1)>0 ");
			}
		}
		else
		{
			if(!"".equals(zdmc)&&!"".equals(defaultVaue))
			{
				buffer.append(" and instr(',"+defaultVaue+",',','||"+zdmc+"||',',1)>0 ");
			}
		}
		return buffer.toString();
	}
	/**
	 * toDo:通过页面编号、字段英文名称读出对应的限制条件
	 * @param ymbh
	 * @param zdywmc
	 * @return xztj
	 */
	@SuppressWarnings("unchecked")
	public String getQxxztj(String ymbh,String zdywmc)
	{
		String xztj ="";
		if(fwjlgxList!=null&&!fwjlgxList.isEmpty())
		{
			for (Iterator iterator = fwjlgxList.iterator(); iterator.hasNext();) {
				AppsysQxfwjlgx appsysQxfwjlgx = (AppsysQxfwjlgx) iterator
						.next();
				if(appsysQxfwjlgx.getYmbh().equals(ymbh)&&appsysQxfwjlgx.getZdywmc().equals(zdywmc))
				{
					xztj += appsysQxfwjlgx.getXztj()+",";
				}
			}
		}
		return xztj;
	}
	/**
	 * toDo:通过页面编号、字段英文名称读出对应日期类型限制条件
	 * @param ymbh
	 * @param zdywmc
	 * @return xzrq
	 */
	@SuppressWarnings("unchecked")
	public String[] getQxxzrq(String ymbh,String zdywmc)
	{
		String[] xzrq = new String[2];
		if(fwjlgxList!=null&&!fwjlgxList.isEmpty())
		{
			for (Iterator iterator = fwjlgxList.iterator(); iterator.hasNext();) {
				AppsysQxfwjlgx appsysQxfwjlgx = (AppsysQxfwjlgx) iterator
						.next();
				if(appsysQxfwjlgx.getYmbh().equals(ymbh)&&appsysQxfwjlgx.getZdywmc().equals(zdywmc))
				{
					xzrq[0] = appsysQxfwjlgx.getXztj();
					xzrq[1] = appsysQxfwjlgx.getXstj();
				}
			}
		}
		return xzrq;
	}
	/**
	 * @return the sjbmbh
	 */
	public String getSjbmbh() {
		return sjbmbh;
	}
	/**
	 * @param sjbmbh the sjbmbh to set
	 */
	public void setSjbmbh(String sjbmbh) {
		this.sjbmbh = sjbmbh;
	}
	/**
	 * @return the sjbhmc
	 */
	public String getSjbhmc() {
		return sjbhmc;
	}
	/**
	 * @param sjbhmc the sjbhmc to set
	 */
	public void setSjbhmc(String sjbhmc) {
		this.sjbhmc = sjbhmc;
	}
	/**
	 * @return the sjbmgdbh
	 */
	public String getSjbmgdbh() {
		return sjbmgdbh;
	}
	/**
	 * @param sjbmgdbh the sjbmgdbh to set
	 */
	public void setSjbmgdbh(String sjbmgdbh) {
		this.sjbmgdbh = sjbmgdbh;
	}
	/**
	 * @return the ymgnList
	 */
	public List<AppsysYmgnan> getYmgnList() {
		return ymgnList;
	}
	/**
	 * @param ymgnList the ymgnList to set
	 */
	public void setYmgnList(List<AppsysYmgnan> ymgnList) {
		this.ymgnList = ymgnList;
	}
	public static void main(String[] args) {
		String str = "1,2,3,a,b,2,a";
		System.out.println("buffer: "+StringUtils.removeSameString(str,","));
	}
	/**
	 * toDo:get
	 * @return dlsj
	 */
	public Date getDlsj() {
		return dlsj;
	}
	/**
	 * toDo:set
	 * @param dlsj 
	 */
	public void setDlsj(Date dlsj) {
		this.dlsj = dlsj;
	}
	/**
	 * toDo:get
	 * @return xtmc
	 */
	public String getXtmc() {
		return xtmc;
	}
	/**
	 * toDo:set
	 * @param xtmc 
	 */
	public void setXtmc(String xtmc) {
		this.xtmc = xtmc;
	}
}
